home *** CD-ROM | disk | FTP | other *** search
/ WINMX Assorted Textfiles / Ebooks.tar / Text - Tech - Hacking - Hacking Unix - Part 1.txt < prev    next >
Text File  |  2003-09-27  |  19KB  |  494 lines

  1.                           - HACKING UNIX -
  2.                               PART ONE:
  3.  
  4.                     Security and Vulnerabilities
  5.                  -----------------------------------
  6.  
  7. Completed on 10-17-01 (MM-DD-YY)
  8. By: XT - [DuHo] <http://duho.cjb.net>
  9.  
  10.  
  11. &    ** This is a multi-part tutorial,
  12. &    ** please check our website for other
  13. &    ** parts: 
  14. &    ** http://duho.cjb.net
  15. &
  16. &    Next part, soon to come out (as of 10-17-01):
  17. &        => System Profiling Unices
  18. &
  19. &    AND MORE TO COME!
  20.  
  21.  
  22. ******
  23.  
  24. INDEX:
  25.  
  26. Introduction
  27. 0. - Forword
  28. 1. - Audience
  29. 2. - Conventions
  30. 3. - Orientation
  31.  
  32. 4. - Vulnerabilities
  33.      4.1 - Full Disclosure
  34.             3.1.1 Advantages & Disadvantages
  35.      4.2 - Exploit Code
  36.      4.3 - 'Access Levels' and 'Environments' and 'Security'
  37. 5. - Where do vulnerabilities occur?
  38. 6. - Who finds vulnerabilities
  39. 7. - Last words
  40.  
  41. ****************************************************************
  42.  
  43. 0. Forword
  44.  
  45. Yes, this is another tutorial trying to put 'all-in-one'. As far is I know
  46. there is not a good and recent written tutorial like this. Old texts do
  47. still have a value though, but i think much is obsolete now. Examples of
  48. such tutorials are:
  49.  
  50. * User's Guide 1.0 - Phantom
  51. * A Novice's Guide to Hacking (1989) - The Mentor [LOD]
  52. * NEWBIES HANDBOOK ; HOW TO BEGIN IN THE WORLD OF H/P - PlowskÑ Phreak
  53. * THE ULTIMATE BEGINNER'S GUIDE TO HACKING AND PHREAKING - REVELATION [LOA--ASH]
  54. * Beginners Guide to VAX/VMS Hacking (1989) - ENTITY [Corrupt Computing Canada]
  55. * THE NEOPHYTE'S GUIDE TO HACKING (1993) - Deicide
  56.  
  57. I have read all these when i was first interested and they didn't help me
  58. much in really learning the subject. Especially now much in these
  59. tutorials is outdated and irrelevant. But i think it's not bad to read
  60. them afterall, this is oldskool hacking which is always fun-reading. Also
  61. take a look in the phrack archives (www.phrack.org) in the old issues, for
  62. a look in the past.
  63.  
  64. At first I wanted to release the 'HACKING UNIX' tutorial as a whole. But I
  65. couldn't wait to release it. I decided to break it up in parts and release
  66. it in parts. I will do my best to complete everything a.s.a.p. This part
  67. on 'Vulnerabilities and security' was finished awhile ago though.  And I'm
  68. almost finished with the next part.
  69.  
  70. 1. Audience
  71.  
  72. You're probably using windows and you're interested in hacking. You
  73. searched for hacking sites on the internet and there you found tools
  74. (wares) which you can use to hack other people. You have tried netbus and
  75. back orifice or other tools, you've collected them and put them on a new
  76. 'hacking page'. You found out that you need a strong l33t handle that
  77. reflects your skillz; like "inv1sibl3 predat0r". You have hacked into your
  78. friends' computers and your friends are truly impressed and people phear
  79. you.
  80.  
  81. Allright it's over now. Did you ever try any of your stupid warez against
  82. your internet service provider's webserver uh? Didn't work exactly did it?
  83. Well, I think that's why you're here right? Well, you're still a zombie
  84. and I hope that I'll break the lameness out of you with this tutorial so
  85. you can work on becoming a true and well respected hacker for the
  86. community. You'll find out that hacking is not about the results it will
  87. give you, it's the act itself that drives the hacker. Eventually only a
  88. few of you will survive.
  89.  
  90. 2. Conventions
  91.  
  92. I wanted to make this paper accessible for both beginners and more 
  93. advanced readers. Therefor, explanations (like technical jargon) are 
  94. explained in side-comments.
  95.  
  96. E.g.:
  97.  
  98. ....the inetd superdaemon....
  99. {
  100.     The Inetd superdaemon is a service that handles network 
  101.     connections for network services that use it.
  102. }
  103.  
  104. This way, the more advanced reader isn't bothered with information that he 
  105. already knows, and the beginner is still able to understand what I am 
  106. talking about.
  107.  
  108. 3. Orientation
  109.  
  110. In a nutshell these are the steps the hacker takes:
  111.  
  112. An attacker first searches a system that he interested in.
  113. Then he explores the system and it's weaknesses, break into the system and
  114. get full control over the system, remove the traces of the hack and use
  115. methods like backdoors to keep access to the system.
  116. {
  117.     Exploring the system means evaluating it's security and see if you 
  118.     are capable of breaking in. In this stage you have to make sure 
  119.     you are not showing the victim that you are trying to break in!
  120. }
  121. {
  122.     Breaking into the system means finding vulnerabilities in 
  123.     the configuration of a system, or see if there is a known 
  124.     vulnerability in the software and exploiting them.
  125. }
  126.  
  127. In the first few parts I will cover all the steps the attacker takes. You 
  128. should then understand how attackers attack, and -with some practice- be 
  129. able to do it yourself.
  130. In the later parts (the advanced section) I will go deep into hacking 
  131. issues, I will talk about low-level network attacks, trust relations, 
  132. encryption, authentication and everything.
  133.  
  134. In this first part I skip the information gathering (profiling) of your 
  135. victim, and start off by introducing you with vulnerabilities; the 
  136. problems in systems that make attacks possible.
  137.  
  138. 4. Vulnerabilities
  139.  
  140. Programs have bugs and bugs can often be taken advantage of.
  141. {
  142.     Bugs that can be taken advantage of to bypass security 
  143.     restrictions are called vulnerabilities.
  144. }
  145.  
  146. This chapter introduces you to the community that searches and fixes 
  147. vulnerabilities.
  148.  
  149. If some individual finds a vulnerability in a server application like the 
  150. apache webserver (HTTP server) the individual often notifies the vendor 
  151. (the apache project in this example) of the problem. The vendor then looks 
  152. into the problem and fixes the vulnerability.
  153. The fix is then provided to the users of the apache webserver in the form 
  154. of a work-around, a patch or a new release.
  155.  
  156. People are made aware of the vulnerability in the product they use, and 
  157. fix their servers, or they don't.
  158.  
  159. Because of this, vulnerabilities are often present in certain versions. So 
  160. if the attacker finds out which version of a product the victim uses, he 
  161. might find out that his victim uses a vulnerable version of the product.
  162.  
  163. This being said, the chance of being able to attack the target through a
  164. known vulnerability depends on the degree of detail that the founder of
  165. the problem has disclosed in his publication of the problem.
  166. {
  167.     Papers/Articles that discuss a security vulnerability are called 
  168.     'advisories'.
  169. }
  170.  
  171. 4.1 Full-disclosure
  172.  
  173. __When someone releases the details of a security problem in the degree
  174. that another individual is capable of reproducing the
  175. "state of exploitation"*, we call it a "full-disclosure advisory"__
  176. {
  177.     The "state of exploitation" means 'the compromise of whole or
  178.     part of the target's environment* after bypassing the
  179.     security-policy that the target should have enforced.
  180.  
  181.     Bypassing the intended security restrictions are -ofcourse-
  182.     discussed in the (full-disclosure) advisory.
  183.  
  184.     *What exactly I mean with 'environment' in this context will be 
  185.     explained in chapter 4.3.
  186. }
  187.  
  188. 4.1.1 Advantages and Disadvantages
  189.  
  190. The full-disclosure method has advantages and disadvantages for security.
  191.  
  192. Disadvantages of Full-Disclosure:
  193.  
  194. The disadvantage for security when writing and publishing a full disclosed
  195. advisory is that many people are capable of attacking vulnerable servers.
  196. And as many administrators do not care about vulnerabilities in software
  197. they use, they have a high chance of being hacked by evil people like you
  198. ;-}.
  199.  
  200. Advantages of Full-Disclosure:
  201.  
  202. The advantage of full-disclosure is that security-concious programmers
  203. will learn what programming methods are insecure. It also presses the
  204. vendors of programs to quickly fix their crap and make sure it doesn't
  205. happen again.
  206.  
  207. Full-dislosure has another advantage; admins will feel themselves
  208. pressured to keep their software up-to-date as many people in the public
  209. are capable of exploiting the software.
  210.  
  211. 4.2 Exploit code
  212.  
  213. Full-disclosure reports often include 'exploit-code' which makes it even
  214. easier to reproduce exploitation state, sometimes the 'sploit-code' is
  215. this user-friendly* that a kid could break into a system with it.
  216. {
  217.     *Though, most of the time the (ab)user has to modify the exploit 
  218.     program alittle to make it work against his target.
  219. }
  220.  
  221. Exploit code is simply a program that will automatically reproduce
  222. exploitation state when you point it to a vulnerable server that 
  223. runs the vulnerable software.
  224.  
  225. The exploit-code is supposed to only be used by admins to test if their 
  226. systems are vulnerable. Therefor, some of the exploit code only proves 
  227. that the vulnerability exists without being usable for attackers. Although 
  228. a good attacker knows how to modify the exploit program to fit his needs.
  229.  
  230. When someone releases an advisory but doesn't include an exploit, it often
  231. doesn't take long before someone writes one and submits it to bug tracking 
  232. mailing lists and exploit archive sites.
  233.  
  234. 4.3 'Access Levels' and 'Environments' and 'Security'
  235.  
  236. When an attacker exploits a network service, this often doesn't mean that
  237. the system is fully compromised yet. Most network service programs do not
  238. require full system access for their tasks and are preferred to have
  239. low-privileges.
  240. {
  241.     Privileges involve access control rights on files, network 
  242.     resources, memory access, system calls etc.
  243.  
  244.     This will be called the program's (or users') 'environment' 
  245.     throughout the rest of this guide.
  246. }
  247.  
  248. Though sometimes a network service requires superuser privileges for 
  249. certain tasks. A good process only runs particular tasks with super-user 
  250. privilege and not the whole process.
  251.  
  252. When an attacker compromises whole or part of a target process' the 
  253. attacker atleast has a more flexible environment where it becomes easier 
  254. to gain superuser privileges.
  255. {
  256.     The scenario where the attacker has compromised an environment 
  257.     where he can read files and execute programs is called 'local 
  258.     access'. Many admins don't really care about vulnerabilities in 
  259.     programs that are not accessible through network services and 
  260.     often don't bother to fix these problems because it doesn't seem 
  261.     like a direct threat.
  262. }
  263.  
  264. No system is totally secure, all an admin can do to minimize the danger of
  265. a vulnerable or misconfigured server program, is to minimize the
  266. resources the programs have access to. This minimizes the environment of 
  267. an attacker that gained access to that program's environment and makes it 
  268. harder for the attacker to gain full access.
  269. {
  270.     A good security setup is created by first disabling everything, 
  271.     and then discover what *has* to be enabled.
  272.  
  273.     After that the admin simply fixes known security problems when 
  274.     they come out.
  275. }
  276.  
  277. So security is all about evaluating what privileges a program or user 
  278. needs (and doesn't need).
  279.  
  280. The 'environment' I'm talking about is enforced by the kernel. The kernel 
  281. allows or denies access to files, to network sockets, to I/O devices and 
  282. all.
  283.  
  284. The operating system controls only the program's environment and users's
  285. environment. The programs that provide services to users are responsible 
  286. for restricting user access to their own environment
  287. {
  288.     A webserver has a directory like '/var/www/htdocs' where the 
  289.     DocumentRoot of the HTTP service resides. The webserver program 
  290.     itself is allowed to access the /etc, /usr, /home and /proc 
  291.     directory's by the operating system. So the environment that the 
  292.     operating system provides to the webserver program is much wider 
  293.     than the environment that the webserver provides to site visitors; 
  294.     It only gives read access to /var/www/htdocs/, and all 
  295.     attempts to access directory's beneith htdocs/ are denied by the 
  296.     webserver. Any succesful attempt to break out of the virtual 
  297.     environment that is provided by the webserver is a vulnerability.
  298.  
  299.     Such a vulnerability will give a degree or full access to the webservers
  300.     environment within the system. A full access to the webserver's
  301.     environment means that we can execute programs, browse directory's and
  302.     read all files that the webserver program has access to within 
  303.     the system.
  304. }
  305.  
  306. 5. Where do vulnerabilities occur?
  307.  
  308. Basically vulnerabilities occur in (to list some):
  309.  
  310. - input handling
  311. - configuration errors
  312. - communication
  313. - trust relationships
  314. - authentication handling
  315. - cryptography bugs
  316. - wrong security policy
  317.  
  318. So it happens everywhere... it happens at the vendor of a specific
  319. program. It happens at the operating system vendor which puts programs
  320. into a distribution. It happens when admins install things wrong or set
  321. things wrong. It happens when communication protocols are unreliable. It
  322. happens between communication of programs. It happens when users are
  323. stupid. It happens when two programs on a system form security problems.
  324.  
  325. 5. Who finds vulnerabilities
  326.  
  327. Real hackers find the vulnerabilities.
  328. {
  329.     Hackers search for ways to make a *system do things that shouldn't 
  330.     be possible.
  331.  
  332.     *A system can be anything: a program, a user (person), a    
  333.     protocol.
  334. }
  335.  
  336. A hacker will examine a program on how it works.
  337. {
  338.     This is done for example through tests, reverse engineering or 
  339.     simply reading the *source code.
  340.  
  341.     Source code (for the total beginner) are the programmers' 
  342.     instructions in a certain programming language that make up the 
  343.     program before it is converted into machine language.
  344. }
  345.  
  346. He will learn about the procedures a program takes and he will investigate
  347. whether the methods used are secure. The procedures might rely on other 
  348. software, kernel calls and network communication.
  349.  
  350. To make you understand, here's a security advisory to make you see what I 
  351. mean;
  352.  
  353. ------------------------------------------------------------------------------
  354. Date: Thu, 20 Sep 2001 21:48:34 +0200
  355. From: "Przemyslaw Frasunek" <venglin@freebsd.lublin.pl>
  356. Subject: Local vulnerability in libutil derived with FreeBSD 4.4-RC
  357.          (and earlier)
  358. Organization: babcia padlina ltd.
  359. To: <bugtraq@securityfocus.com>
  360.  
  361. Hello, OpenSSH derived with FreeBSD 4.4 (and earlier) doesn't drop 
  362. privileges before messing with login class capability database. The most 
  363. problematic is:
  364.         if (newcommand == NULL && !quiet_login && !options.use_login) 
  365. {
  366.                 fname = login_getcapstr(lc, "copyright", NULL, NULL);
  367.                 if (fname != NULL && (f = fopen(fname, "r")) != NULL) {
  368.                         while (fgets(buf, sizeof(buf), f) != NULL)
  369.                                 fputs(buf, stdout);
  370.                                 fclose(f);
  371.  
  372. and
  373.                 f = fopen(login_getcapstr(lc, "welcome", "/etc/motd",
  374.                     "/etc/motd"), "r");
  375. [...]
  376.                         while (fgets(buf, sizeof(buf), f))
  377.                                 fputs(buf, stdout);
  378.                         fclose(f);
  379.  
  380. in session.c, which allows to read ANY file in system with superuser
  381. privileges, by defining:
  382.  
  383. default:\
  384.  :copyright=/etc/master.passwd:
  385.  
  386. or
  387.  
  388.  :welcome=/etc/master.passwd: in user's ~/.login_conf. login(1), which is 
  389. suid and spawned by telnetd also is vulnerable to similar attack:
  390.  
  391.     if (!rootlogin)
  392.                 auth_checknologin(lc);
  393. [...]
  394.         (void)setegid(pwd->pw_gid);
  395.         (void)seteuid(rootlogin ? 0 : pwd->pw_uid);
  396.  
  397. Checking for nologin is performed with superuser privileges.
  398. auth_checklogin() is libutil function which displays nologin file, as
  399. defined in login capability database. User can read ANY file in system by
  400. defining:
  401.  
  402. default:\
  403.  :nologin=/etc/master.passwd:
  404.  
  405. FreeBSD core team has been aleady informed and official patches were
  406. incorporated into CVS repository *before* 4.4-RELEASE, although 4.4-RC and
  407. earlier verions are vulnerable and needs to be patched with: 
  408.  
  409. http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/lib/libutil/login_cap.c?rev=1.17.2.3&content-type=text/plain
  410.  
  411. Official advisory is pending. It's possible, that other *BSD systems,
  412. supporting login capability database are also vulnerable.
  413.  
  414. --
  415. * Fido: 2:480/124 ** WWW: http://www.frasunek.com/ ** NIC-HDL: PMF9-RIPE
  416. *
  417. * Inet: przemyslaw@frasunek.com ** PGP: D48684904685DF43EA93AFA13BE170BF
  418. *
  419. ------------------------------------------------------------------------------
  420.  
  421. This is a nice full-disclosure advisory example: It explains the
  422. programming error, the way it can be exploited and it links to the 
  423. vendor's patch.
  424.  
  425. I don't expect you to understand this advisory, but you should have 
  426. figured out how it can be exploited (on unpatched systems).
  427.  
  428. What it says is that a user can create a file called '.login_conf' (which
  429. is probably already there) in their home directory, and when putting a
  430. line like:
  431.  
  432. ----
  433. default:\
  434. :copyright=/etc/master.passwd:
  435. ----
  436.  
  437. or
  438.  
  439. ----
  440. default:\
  441. :welcome=/etc/master.passwd:
  442. ----
  443.  
  444. in the .login_conf file, the login process will then read that file once
  445. you re-login. And because it still has root privileges (it doesn't return
  446. to it's normal user-id) you can place any file name in the .login_conf,
  447. and it will be displayed when you log in! This means you can read the
  448. master.passwd file where the password-hashes for all users are stored.
  449. Ofcourse that file should not readable for a normal user. But if you are
  450. able to read it, like in this case, you can perform a brute-force attack
  451. using password-crackers like CRACK-5.0, and then it will only be a matter
  452. of time before you the root password is recovered.
  453. {
  454.     Though when the root users' password consists of more than 8 
  455.     characters and he uses a combination of numeric and alphanumeric 
  456.     and other characters as a password, it might take the fastest 
  457.     computer on earth over a year to crack it.
  458. }
  459.  
  460. Now back to the subject...
  461. Note that the hacker had first informed the vendor FreeBSD which created a
  462. patch. After the patch was released, the hacker posted the vulnerability
  463. information as full-disclosure advisory to the BugTraq mailing list and
  464. included a link to the patch (the fix) for the bug which FreeBSD released.
  465.  
  466. There are also people that don't report bugs to vendors and the public and
  467. use their information for their own sake.
  468.  
  469. There are alot people in the underground (black-hat hackers)  that keep
  470. the information to themselves. Exploits which are not publicated are
  471. called zero-day's (0-day).
  472.  
  473. There is nothing you can do about that, you can only minimize the risk by 
  474. disabling services that you don't need. And you can restrict service 
  475. programs that you do need as explained in chapter 4.3.
  476.  
  477. 7. Last words
  478.  
  479. I hope that you understand the basic picture of security and 
  480. vulnerabilities.
  481.  
  482. Keep your eyes open for the following parts:
  483. VISIT http://duho.cjb.net/
  484.  
  485. You are encouraged to spread this file but don't modify it.
  486.  
  487. XT (duho@my.security.nl): [DuHo] 2001
  488.  
  489. -EOF-
  490. Size: 20480 bytes
  491. chars: 18821
  492. Words: 2902
  493. Lines: 459
  494.